//
//  RegisterViewController.swift
//  BookStore2.0
//
//  Created by hw on 2022/5/31.
//
import UIKit

class RegisterViewController: UIViewController {

    @IBOutlet weak var UserName: UITextField!
    
    @IBOutlet weak var pwd1: UITextField!
    
    @IBOutlet weak var pwd2: UITextField!
    let dftinfo=UserDefaults.standard
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    @IBAction func Register(_ sender: Any) {
        if pwd1.text==pwd2.text {
            let username=UserName.text!
            let password=pwd1.text!
            dftinfo.set(username, forKey: "userName")
            dftinfo.set(password, forKey:"passwd")
            let p=UIAlertController(title:"注册成功",message:"新用户已注册！",preferredStyle:.alert)
            p.addAction(UIAlertAction(title:"确定",style:.default,handler:{
                (
                    act:UIAlertAction)in self.dismiss(animated:true,completion:nil)
            }))
            present(p,animated:false,completion:nil)
        }
        else{
            let p=UIAlertController(title:"注册失败",message:"请检查两次输入的密码是否一致。",preferredStyle:.alert)
            p.addAction(UIAlertAction(title:"确定",style:.default,handler:{
                (
                    act:UIAlertAction)in self.pwd2.text=""
            }))
            present(p,animated:false,completion:nil)
        }
    }
}
